<?php

namespace app\models;
use yii\db\ActiveRecord;

class AdminUser extends ActiveRecord
{

    public $user_id;
    public $type;
    public $user_name;
    public $password;
    public $open_id;
    public $mobile;
    public $del_flag;

    public static  function tableName(){
        return "hcps_user";
    }
    public function attributeLabels(){
        return [
            'user_name'=>'账户',
            'password'=>'密码',
            'rememberMe'=>'记住我'
        ];

    }

    public function rules()
    {
        return [
            // username and password are both required
            [['username', 'password'], 'required'],
            // rememberMe must be a boolean value
            ['rememberMe', 'boolean'],
            // password is validated by validatePassword()
            ['password', 'validatePassword'],
        ];
    }

//    private static $users = [
//        '100' => [
//            'id' => '100',
//            'username' => 'admin',
//            'password' => 'admin',
//            'authKey' => 'test100key',
//            'accessToken' => '100-token',
//        ],
//        '101' => [
//            'id' => '101',
//            'username' => 'demo',
//            'password' => 'demo',
//            'authKey' => 'test101key',
//            'accessToken' => '101-token',
//        ],
//    ];


    /**
     * @inheritdoc
     */
//    public static function findIdentity($id)
//    {
//        return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
//    }

    /**
     * @inheritdoc
     */
//    public static function findIdentityByAccessToken($token, $type = null)
//    {
//        foreach (self::$users as $user) {
//            if ($user['accessToken'] === $token) {
//                return new static($user);
//            }
//        }
//        return null;
//    }

    /**
     * Finds user by username
     *
     * @param string $username
     * @return static|null
     */
    public static function findByUsername($username)
    {
        return parent::find()->where(['deleted' => false]);
    }

    /**
     * @inheritdoc
     */
//    public function getId()
//    {
//        return $this->id;
//    }

    /**
     * @inheritdoc
     */
//    public function getAuthKey()
//    {
//        return $this->authKey;
//    }

    /**
     * @inheritdoc
     */
//    public function validateAuthKey($authKey)
//    {
//        return $this->authKey === $authKey;
//    }

    /**
     * Validates password
     *
     * @param string $password password to validate
     * @return boolean if password provided is valid for current user
     */
    public function validatePassword($password)
    {
        return $this->password === $password;
    }
}
